package mess;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_1237 {
    public static void main(String[] args) {

    }

    private static List<List<Integer>> findSolution(CustomFunction customfunction, int z) {
        List<List<Integer>> res = new ArrayList<>();

        //枚举
        for (int i = 1; i <= z; i++) {
            for (int j = 1; j <= z; j++) {
                if (customfunction.f(i, j) == z){
                    List<Integer> list = new ArrayList<>();
                    list.add(i);
                    list.add(j);
                    res.add(list);
                    break;
                }
            }
        }

        //二分
        for (int i = 1; i <= z; i++) {
            int l = 1;
            int r = z;
            while (l <= r){
                int m = (l + r) / 2;
                if (customfunction.f(i, m) == z){
                    List<Integer> list = new ArrayList<>();
                    list.add(i);
                    list.add(m);
                    res.add(list);
                    break;
                }
                //目标在左半段
                if (customfunction.f(i, m) > z)
                    r = m - 1;
                //目标在右半段
                else
                    l = m + 1;
            }
        }
        return res;
    }
}

interface CustomFunction {
    public int f(int x, int y);
}
